package sy7;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntergerStack{
	public Integer push(Integer item);
	public Integer pop(); 
	public Integer peek(); 
	public boolean empty();
	public int size();
}

class ArrayListIntergerStack implements IntergerStack {
	
	private List<Integer> list;
	
	public ArrayListIntergerStack() {
		list = new ArrayList<Integer>();
	}

	@Override
	public Integer push(Integer item) {
		if(item==null)
			return null;
		list.add(item);
			return item;
	}

	@Override
	public Integer pop() {
		if(list.isEmpty())
			return null;
		return list.remove(list.size()-1);
	}

	@Override
	public Integer peek() {
		if(list.isEmpty())
			return null;
		return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		if(!list.isEmpty())
			return false;
		else 
			return true;
	}

	@Override
	public int size() {
		return list.size();
	}

	@Override
	public String toString() {
		return list.toString();
	}
}
public class Sy71 {
		
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int m = input.nextInt();
		ArrayListIntergerStack s = new ArrayListIntergerStack();
		for (int i = 0; i <m; i++) {
			Integer a=input.nextInt();
			System.out.println(s.push(a));
		}
		System.out.println(s.peek() + "," + s.empty() + "," + s.size());
		System.out.println(s);
		int x=input.nextInt();
		for(int i=x;i>0;i--){
			Integer b=s.pop();
			System.out.println(b);
		}
		System.out.println(s.peek() + "," + s.empty() + "," + s.size());
		System.out.println(s);
	}
		
}


